package org.xin.security.service.impl;


import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.xin.common.constant.Constants;
import org.xin.common.util.XinUtil;
import org.xin.framework.base.service.impl.IBaseServiceImpl;
import org.xin.framework.constant.DataStatus;
import org.xin.security.mapper.SysMenuSecurityMapper;
import org.xin.security.pojo.entity.SysMenuSecurity;
import org.xin.security.service.ISysMenuSecurityService;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 系统模块-菜单安全表 服务实现类
 * </p>
 *
 * @author: xin
 * @date: Create in 2021-10-02
 */
@Slf4j
@Service
public class SysMenuSecurityServiceImpl extends IBaseServiceImpl<SysMenuSecurity, SysMenuSecurityMapper> implements ISysMenuSecurityService {
    @Override
    public List<SysMenuSecurity> selectByPermission(String permission) {
        String[] arr = permission.split(Constants.COLON_SPLIT);
        if (arr.length != 3) {
            return null;
        }
        StringBuffer per = new StringBuffer();
        for (int i=0; i< arr.length; i++) {
            if (XinUtil.equal(arr[i], Constants.All_SIGN)) {
                per.append("%");
            } else {
                per.append(arr[i]);
            }
            if (i != arr.length - 1) {
                per.append(Constants.COLON_SPLIT);
            }
        }
        lambdaQueryWrapper()
                .like(SysMenuSecurity::getPermission, per)
                .eq(SysMenuSecurity::getMenuStatus, DataStatus.ENABLE.ordinal());
        return baseMapper.selectList(lambdaQueryWrapper);
    }
}
